<?php
/**
 * @user:andy
 * @date:2021/7/5
 * @company:http://www.sjdphp.com
 * @desc:
 */

namespace app\common\lib\image;

use app\common\server\SystemLog;
use \think\facade\Filesystem;
class LocalhostImg implements BaseImg
{

    public static function uploadImg($file)
    {
        if(empty($file)) return ['code' => 0,'msg' => '参数不能为空'];

        try{
            ## 开始上传
            $saveName = Filesystem::disk("public")->putFile("topic",$file,'md5');
        }catch(\Exception $e){
            SystemLog::insertLog($e->getMessage());
        }

        if(!empty($saveName)){
            return ['code' => 1,'msg' => '上传成功','path' => "/storage/" . str_replace('\\','/',$saveName)];
        }
    }

    public static function delImg($file)
    {
        // TODO: Implement delImg() method.
    }


    public static function uploadKindImg($file)
    {
        if(empty($file)) return array('error' => 1,'message' => '参数不能为空');

        try{
            ## 开始上传
            $saveName = Filesystem::disk("public")->putFile("topic",$file,'md5');
        }catch(\Exception $e){
            SystemLog::insertLog($e->getMessage());
        }

        if(!empty($saveName)){
            return array("error" => 0,"url" => "/storage/" . str_replace('\\','/',$saveName));
        }
    }
}